Gemini FDE
Certify
arrow_backBack to roadmap
smart_toy AGENTS · DEEP DIVE

The agentic loop & hub-and-spoke orchestration.

One model call rarely finishes the job. Agents run a loop — call, act, observe, repeat — and the most reliable multi-agent systems wire those loops into a hub-and-spoke shape. Here's how the loop terminates, why a coordinator beats a free-for-all, and the rules that keep it from melting down.

schedule8 min read link3 cited sources hubPairs with Module 5

The hub-and-spoke / orchestrator-worker pattern is documented in Anthropic's “How we built our multi-agent research system” (2025) and “Building effective agents.” Diagrams below are original visualizations built for this lesson.

1 · The agentic loop

An agent isn't a single completion — it's a loop. You call the model, and if it wants to use a tool, you run that tool, feed the result back, and call again. The loop continues until the model signals it's finished. The one thing that controls termination is stop_reason: end_turn means the model is done; tool_use means it's asking you to run a tool.

agent_loop.py
# The agentic loopwhile True: response = client.messages.create( model="claude-sonnet-4", max_tokens=4096, tools=tools, messages=messages, ) # KEY: stop_reason controls the loop if response.stop_reason == "end_turn": break # Claude is done if response.stop_reason == "tool_use": block = next(b for b in response.content if b.type == "tool_use") result = execute_tool(block.name, block.input) messages.append({"role": "assistant", "content": response.content}) messages.append({"role": "user", "content": [{ "type": "tool_result", "tool_use_id": block.id, "content": result, }]})
target
Tip
When asked how to terminate the loop, the answer is always checking stop_reason. Distractors: parsing the text content, setting an iteration limit, or watching token counts.
The loop, as a flow
Call model messages.create() stop_ reason? end_turn ✓ Done tool_use execute_tool() append tool_result loop back

Figure 1. Original diagram of the tool-use loop. See Building effective agents.

2 · From one agent to many: hub-and-spoke

When a task is too broad for one context window, you don't make the agent bigger — you split it. In the orchestrator-worker (a.k.a. hub-and-spoke) pattern, a central lead agent plans the work and delegates pieces to specialized subagents, each running its own loop in its own isolated context. Anthropic's multi-agent research system is the canonical example: a lead agent spawns 3–5 subagents that search in parallel, then a separate citation pass attributes the sources.

Hub-and-spoke for agents

One coordinator, many isolated workers. Workers never talk to each other — every decision flows through the hub.

User query one ask Lead Agent the HUB plan · delegate · synthesize Synthesized answer 🔍 Search subagent 📄 Docs subagent 🧮 Analysis subagent ✅ Citation subagent own context · own tools own context · own tools own context · own tools own context · own tools

Figure 2. Original illustration of the orchestrator-worker / hub-and-spoke topology described in Anthropic (2025).

3 · Why the hub wins

The alternative — a flat “swarm” where agents talk to each other and share state — is flexible but nearly impossible to debug. Constraining the topology so workers only talk to the hub buys four concrete advantages:

crop_free
Context isolation
Each subagent gets a fresh window with only its slice of the task — no cross-contamination, no rot from the others' noise.
build
Focused tool access
Give each worker only the 4–5 tools its specialty needs. Fewer tools, fewer wrong turns.
bolt
Parallel execution
Multiple subagents run at once, covering far more ground than one sequential agent could.
filter_alt
Clean synthesis
The hub merges condensed findings without inheriting each worker's exploration noise.
Multi-agent vs. single agent
baseline +90.2% Single agentHub + subagents

Figure 3. On Anthropic's internal research eval, a Claude Opus 4 lead with Sonnet 4 subagents beat single-agent Opus 4 by 90.2% — at roughly 15× the tokens. Original chart; data from Anthropic (2025).

4 · Spawning workers: the Task tool

Subagents are spawned with a dedicated tool. Three configuration rules matter for the exam and in practice:

  • The coordinator's allowedTools must include "Task" to enable subagent spawning.
  • Each Task call specifies that subagent's prompt, tools, and context. Multiple Task calls in one response run in parallel.
  • fork_session branches a session for parallel exploration without polluting the parent's context.
rule
Context-passing rule
Pass only the context specific to each subagent's task. Never hand a worker the full coordinator history — it wastes tokens and confuses the subagent with irrelevant information.

“Workers never talk to each other. Every decision about what comes next lives in the orchestrator.”

— the core discipline of hub-and-spoke

When NOT to reach for it

Hub-and-spoke shines on breadth-first work that splits into independent strands. It's a poor fit for tightly interdependent tasks like most coding, where one decision constrains the next — and it costs ~15× the tokens, so reserve it for problems where the answer's value clearly outweighs the spend.

⚡ Key takeaways
  • check_circleThe agentic loop terminates on stop_reason == "end_turn"; "tool_use" means run a tool and loop again.
  • check_circleHub-and-spoke = one coordinator, many isolated subagents. Workers report to the hub, never to each other.
  • check_circleSpawn with the Task tool (needs allowedTools: "Task"); pass each worker only its relevant context.

References & sources

  1. Anthropic (2025). How we built our multi-agent research system. anthropic.com/engineering/multi-agent-research-system
  2. Anthropic (2024). Building effective agents. anthropic.com/engineering/building-effective-agents
  3. Anthropic. Tool use with Claude (the agentic loop & stop_reason). docs.anthropic.com — tool use
Up next · Module 5
Agent Evaluation & Orchestration
arrow_forward